package cn.player.media.entity;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import cn.player.media.util.ParseUtil;

/**
 * 当前频道 直播Epg数据
 * @author zengliang
 *
 */
public class LiveEpg {
	
	/*
	 * 正在直播节目
	 */
	private String isLive;
	/*
	 * 正在直播节目开始时间
	 */
	private long liveSt;
	/*
	 * 频道名称
	 */
	private String channelName;
	/*
	 * 节目列表
	 */
	private List<Program> program;
	
	
	
	
	
	/**
	 * @return the isLive
	 */
	public String getIsLive() {
		return isLive;
	}





	/**
	 * @param isLive the isLive to set
	 */
	public void setIsLive(String isLive) {
		this.isLive = isLive;
	}





	/**
	 * @return the liveSt
	 */
	public long getLiveSt() {
		return liveSt;
	}





	/**
	 * @param liveSt the liveSt to set
	 */
	public void setLiveSt(long liveSt) {
		this.liveSt = liveSt;
	}





	/**
	 * @return the channelName
	 */
	public String getChannelName() {
		return channelName;
	}





	/**
	 * @param channelName the channelName to set
	 */
	public void setChannelName(String channelName) {
		this.channelName = channelName;
	}





	/**
	 * @return the program
	 */
	public List<Program> getProgram() {
		return program;
	}





	/**
	 * @param program the program to set
	 */
	public void setProgram(List<Program> program) {
		this.program = program;
	}





	public class Program{
		/*
		 * title
		 */
		private String t;
		/*
		 * startTime 毫秒值
		 */
		private long st;
		/*
		 * endTime
		 */
		private long et;
		/*
		 * showTime mm:ss
		 */
		private String showTime;
		/*
		 * duration 节目时长
		 */
		private long duration;
		
		private boolean isSubscribe;
		
		/**
		 * @return the t
		 */
		public String getT() {
			return t;
		}
		/**
		 * @param t the t to set
		 */
		public void setT(String t) {
			this.t = t;
		}
		/**
		 * @return the st
		 */
		public long getSt() {
			return st;
		}
		/**
		 * @param st the st to set
		 */
		public void setSt(long st) {
			this.st = st;
		}
		/**
		 * @return the et
		 */
		public long getEt() {
			return et;
		}
		/**
		 * @param et the et to set
		 */
		public void setEt(long et) {
			this.et = et;
		}
		/**
		 * @return the showTime
		 */
		public String getShowTime() {
			return showTime;
		}
		/**
		 * @param showTime the showTime to set
		 */
		public void setShowTime(String showTime) {
			this.showTime = showTime;
		}
		/**
		 * @return the duration
		 */
		public long getDuration() {
			return duration;
		}
		/**
		 * @param duration the duration to set
		 */
		public void setDuration(long duration) {
			this.duration = duration;
		}
		public boolean isSubscribe() {
			return isSubscribe;
		}
		public void setSubscribe(boolean isSubscribe) {
			this.isSubscribe = isSubscribe;
		}
	}
	
	/**
	 * 根据频道名称获取最近7天频道epg列表
	 * test url = "http://tv.cntv.cn/api/epg/info2?c=cctv13&d=0"
	 * @param obj Json实体
	 * @param channel 频道名称  cctv13
	 * @return Map<yyyyMMdd,LiveEpg>
	 */
	public static Map<String,LiveEpg> getTimeShiftEpgList(JSONObject obj, String channel){
		try {
			Map<String,LiveEpg> map = new HashMap<String, LiveEpg>();
			Iterator<?> it = obj.keys();
			while (it.hasNext()) {
				String keyDate = it.next().toString(); 
				LiveEpg epgLists = ParseUtil.parseDataToEntity(obj.optJSONObject(keyDate), channel, LiveEpg.class);
				map.put(keyDate, epgLists);
			}
			return map.size() == 0 ? null : map;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return null; 
	}

}
